package com.huatai.exchange.bootup.controller;

import com.faneui.bootup.controller.AbstractRestController;
import com.faneui.common.exception.BusinessException;
import com.faneui.common.utils.BeanMapper;
import com.faneui.common.utils.ListUtils;
import com.huatai.exchange.dal.model.ExcExchangeRecord;
import com.huatai.exchange.facade.ExchangeRecordController;
import com.huatai.exchange.facade.bean.ExchangeRecordVo;
import com.huatai.exchange.facade.bean.QueryExchangeRecordVoListResp;
import com.huatai.exchange.service.ExcExchangeRecordService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "exchangerecord")
@Api("数据文件交换记录查询")
public class ExchangeRecordControllerImpl extends AbstractRestController implements ExchangeRecordController {

    @Autowired
    private ExcExchangeRecordService excExchangeRecordService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public QueryExchangeRecordVoListResp queryExchangeRecordVoList(ExchangeRecordVo exchangeRecordVo) throws BusinessException {
        QueryExchangeRecordVoListResp resp = new QueryExchangeRecordVoListResp();
        try {
            ExcExchangeRecord param = BeanMapper.map(exchangeRecordVo, ExcExchangeRecord.class);
            List<ExcExchangeRecord> records = excExchangeRecordService.queryExcExchangeRecordList(param);
            if (ListUtils.isNotEmpty(records)) {
                List<ExchangeRecordVo> vos = BeanMapper.mapList(records,ExchangeRecordVo.class) ;
                resp.setExchangeRecordVos(vos);
            }
        } catch (Exception ex) {
            resp.setSuccess(false);
            resp.setMsg(ex.getMessage());
        }
        return resp;
    }
}
